package com.mindbook.vip.gawxchatinfo.service.impl.nostrum;

import com.mindbook.vip.gawxchatinfo.entity.nostrum.PrimaryHepaticCarcinomaClinicalExaminationGuidance;
import com.mindbook.vip.gawxchatinfo.exception.business.BusinessProcessException;
import com.mindbook.vip.gawxchatinfo.mapper.nostrum.PrimaryHepaticCarcinomaClinicalExaminationGuidanceMapper;
import com.mindbook.vip.gawxchatinfo.service.nostrum.PrimaryHepaticCarcinomaClinicalExaminationGuidanceService;
import com.mindbook.vip.gawxchatinfo.utils.array.ArrayUtils;
import com.mindbook.vip.gawxchatinfo.utils.result.ResultEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PrimaryHepaticCarcinomaClinicalExaminationGuidanceServiceImpl implements PrimaryHepaticCarcinomaClinicalExaminationGuidanceService {

    @Autowired
    private PrimaryHepaticCarcinomaClinicalExaminationGuidanceMapper mapper;


    @Override
    public String businessProcess(PrimaryHepaticCarcinomaClinicalExaminationGuidance p) {
        switch (validateC2(p)) {
            case 1:
                //筛查
                return "G1";
            case 2://可疑肝肿瘤确诊
                switch (validateC3(p)) {
                    case 1:
                        if (validateC4(p) == 1) {
                            return "G2";
                        } else if (validateC4(p) == 2) {
                            return "G3";
                        } else if (validateC4(p) == 3) {
                            return "G4";
                        } else {
                            throw new BusinessProcessException(ResultEnum.PARAMS_EMPTY.getCode(), "肿瘤大小不在允许范围内");
                        }
                    case 2:
                        if (validateC5(p)) {
                            return "G5";
                        } else {
                            return "G6";
                        }
                    case 3:
                        return "G7";
                }

            case 3:
                switch (validateC3(p)) {
                    case 1:
                        if (validateC4(p) == 2) {
                            if (validateC5(p)) {
                                return "G8";
                            } else {
                                return "G9";
                            }

                        } else if (validateC4(p) == 3) {
                            if (validateC5(p)) {
                                return "G10";
                            } else {
                                return "G11";
                            }
                        }
                        break;
                    case 2:
                        if (validateC5(p)) {
                            return "G5";
                        } else {
                            return "G6";
                        }
                    case 3:
                        return "G7";
                }
                break;
        }
        return null;
    }



    /**
     * 判断一下就医情景的值
     *
     * @param p
     * @return
     */
    private Integer validateC2(PrimaryHepaticCarcinomaClinicalExaminationGuidance p) {
        Integer medicalSituation = p.getMedicalSituation();
        if (medicalSituation == null) {
            throw new BusinessProcessException(ResultEnum.PARAMS_EMPTY.getCode(), "就医情景未选择");
        }
        switch (medicalSituation) {
            case 1://筛查
            case 2://可疑肝肿瘤确诊
            case 3://确诊后治疗前检查
                return medicalSituation;
            default:
                throw new BusinessProcessException(ResultEnum.PARAMS_EMPTY.getCode(), "就医情景值超出预定值");
        }
    }

    /**
     * 判断当前的轻重缓急的状况
     * 判断算法：
     * 1.症状中有d或者e情况属于急诊
     * 2.症状中有f情况属于恶液质
     * 3.其他，属于普通
     * 注意：判断算法中并没有关于体征的状况判断。
     *
     * @param p
     * @return 身体状况：1.普通，2.急诊，3.恶病质
     */
    private Integer validateC3(PrimaryHepaticCarcinomaClinicalExaminationGuidance p) {
        Integer flag = 1;
        String array = p.getSymptom();
        //当用户并没有选择身体状况的时候，默认为普通
        if (array.length() == 0) {
            return flag;
        }
        //判断当前是否有恶液质
        String[] symptom = array.split(",");
        String[] eyz = new String[]{"f"};
        if (ArrayUtils.validateIncloud(symptom, eyz)) {
            flag = 3;
            return flag;
        }

        String[] jz = new String[]{"d", "e"};
        if (ArrayUtils.validateIncloud(symptom, jz)) {
            flag = 2;
        }
        return flag;
    }


    /**
     * 获取当前的肿瘤大小问题
     * @param p
     * @return
     */
    private Integer validateC4(PrimaryHepaticCarcinomaClinicalExaminationGuidance p){
        if(p.getTumorSize()==null){
            throw new BusinessProcessException(ResultEnum.PARAMS_EMPTY.getCode(),"肿瘤大小未选择");
        }
        return p.getTumorSize();
    }


    /**
     * 校验当前是否选中了合并疾病
     *
     * @param p
     * @return
     */
    private boolean validateC5(PrimaryHepaticCarcinomaClinicalExaminationGuidance p) {
        String otherDiseases = p.getOtherDiseases();
        if (otherDiseases == "") {
            return false;
        }
        String[] split = otherDiseases.split(",");
        if (split.length > 0) {
            return true;
        }
        return false;
    }

    @Override
    public Integer removeByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public Integer add(PrimaryHepaticCarcinomaClinicalExaminationGuidance primaryHepaticCarcinomaClinicalExaminationGuidance) {
        return null;
    }

    @Override
    public Integer put(PrimaryHepaticCarcinomaClinicalExaminationGuidance primaryHepaticCarcinomaClinicalExaminationGuidance) {
        return null;
    }

    @Override
    public Integer addSelective(PrimaryHepaticCarcinomaClinicalExaminationGuidance primaryHepaticCarcinomaClinicalExaminationGuidance) {
        return mapper.insertSelective(primaryHepaticCarcinomaClinicalExaminationGuidance);
    }

    @Override
    public PrimaryHepaticCarcinomaClinicalExaminationGuidance findByPrimaryKey(Integer id) {
        return null;
    }

    @Override
    public Integer saveByPrimaryKeySelective(PrimaryHepaticCarcinomaClinicalExaminationGuidance primaryHepaticCarcinomaClinicalExaminationGuidance) {
        return null;
    }

    @Override
    public Integer saveByPrimaryKey(PrimaryHepaticCarcinomaClinicalExaminationGuidance primaryHepaticCarcinomaClinicalExaminationGuidance) {
        return null;
    }

    @Override
    public List<PrimaryHepaticCarcinomaClinicalExaminationGuidance> findAll() {
        return null;
    }
}
